Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

purgecss

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

purgecss

Remove unused css selectors

  • 4.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
757K
decreased by-0.35%
Maintainers
2
Weekly downloads
 
Created

What is purgecss?

PurgeCSS is a tool to remove unused CSS. It can be used as part of your development workflow to reduce the size of your CSS files by removing unused selectors.

What are purgecss's main functionalities?

Basic Usage

This code demonstrates the basic usage of PurgeCSS. It scans HTML files and CSS files to remove unused CSS selectors.

const PurgeCSS = require('purgecss');
const purgeCSSResults = new PurgeCSS().purge({
  content: ['**/*.html'],
  css: ['**/*.css']
});
console.log(purgeCSSResults);

Using with PostCSS

This code shows how to integrate PurgeCSS with PostCSS. It processes CSS files and removes unused selectors based on the content of HTML files.

const postcss = require('postcss');
const purgecss = require('@fullhuman/postcss-purgecss');

postcss([
  purgecss({
    content: ['./src/**/*.html']
  })
]).process(css, { from: 'src/app.css', to: 'dist/app.css' })
  .then(result => {
    console.log(result.css);
  });

Using with Webpack

This code demonstrates how to use PurgeCSS as a Webpack plugin. It scans the specified paths for content and removes unused CSS selectors during the Webpack build process.

const PurgeCSSPlugin = require('purgecss-webpack-plugin');
const glob = require('glob');
const path = require('path');

module.exports = {
  // other webpack config
  plugins: [
    new PurgeCSSPlugin({
      paths: glob.sync(`${path.join(__dirname, 'src')}/**/*`, { nodir: true }),
    }),
  ],
};

Other packages similar to purgecss

Keywords

FAQs

Package last updated on 29 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc